<%@ page language="java" contentType="text/html; charset=gb2312"
	pageEncoding="UTF-8"%>
<%@ page import="cal.*,org.apache.lucene.search.* " %>
<%@ page import=" java.util.*,java.io.*,org.wltea.analyzer.*,javax.xml.parsers.*,org.apache.lucene.document.*,org.xml.sax.*, org.xml.sax.helpers.*" %>
<html>
	<head> 
 <%
    request.setCharacterEncoding("gb2312");
    String sogou = "F:\\j2me\\PicSearch\\file\\sogou.xml";
    String three = "F:\\j2me\\PicSearch\\file\\threeMonth.xml";
    String indexPath = "F:\\j2me\\PicSearch\\index";
    
    String query= request.getParameter("query");
    String size= request.getParameter("size");
    String debug[] = request.getParameterValues("debug");
 	System.out.println("Query:"+query);
	System.out.println("Size:"+size);
	String debugInfo="";
 	for(int i=0;debug!=null && i<debug.length;i++)
 		debugInfo+=debug[i]+" ";
 	System.out.println("debugInfo:"+debugInfo);
 	
    cal.IndexHTML index =  cal.IndexHTML.get_instance();  
    cal.mySearcher search = new mySearcher();
    
    if(debugInfo.isEmpty())
    	index.flag_for_index = true;
    else
    	index.flag_for_index = false;
    if(debugInfo.contains("大图"))
    	 index.BigPrior=false;
    else
    	 index.BigPrior=true;
    if(debugInfo.contains("比例"))
    	search.ScalePrior=false;
    else
    	search.ScalePrior=true;
    
    if(debugInfo.contains("全部"))
    {
    	search.ScalePrior=true;
        index.BigPrior=true;
        index.flag_for_index=false;
    }
    
    System.out.println("不建索引 "+index.flag_for_index+"不大图优先"+ !index.BigPrior+"不比例优先"+!search.ScalePrior);
    if(index.flag_for_index == false) 
    {
    	index.index(sogou,three,indexPath);
    	index.flag_for_index = true;
    } 
    search.size = size;
    long start = new Date().getTime();
    List<Element> hits  = search.find(query,indexPath);
    String simi_word = search.simi_word;
    long end   = new Date().getTime();
    double time= (end-start)/1000.0;
 %>
 
 		<title> 结果展示界面</title>
	</head>
 <body bgcolor="#fffff0">
 
  <table border="0" align="left">
	<tr>
		<td>
		 <form method="post" action="result.jsp">
		  <table border="0" align="left">
			<tr align="left">
				<td > <a href="index.jsp"><img src="temp.jpg" alt="Welcome to Search!" width="50"> </a> </td>
				<td >  <input type="text" style="width: 150px;height:25px;font-size:10pt" name="query"  value="<% out.print(query);%>" /> </td>
				<td>   <input type="submit" name="Submit1" value="Search"> 	</td>
			</tr>
			<tr align="left" >
			    <td> <input type="radio" name="size" value="全部图片" checked='checked'> 全部图片</td>
			    <td> <input type="radio" name="size" value="大图片"> 大图片</td> 
			    <td> <input type="radio" name="size" value="中图片"> 中图片</td> 
			    <td> <input type="radio" name="size" value="小图片"> 小图片</td> 			
			</tr>
				<tr align="left" >
			    <td> <input type="checkbox" name="debug" value="不是大图优先">不是大图优先 </td>
			    <td> <input type="checkbox" name="debug" value="不是大图优先"> 不是比例优先</td> 	
			     <td> <input type="checkbox" name="debug" value="全部优先"> 全部优先</td>			
			</tr>
		  </table>
		 </form>
		</td>
	</tr>
	<tr>
		<td>
		   <table border="0" align="left" bgcolor=”#fffff2“>
			<tr>
			    <td align="left" style="width: 150px;">
				   <p> <% out.print("相关搜索:"+simi_word);%> </p>
				</td>
				<td align="right" style="width: 800px;">
				   <p> <% out.print("Search一下，找到相关图片约"+search.totolResultNum+"张,用时"+time+"秒");%> </p>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<table border="0" align="center">
			<tr>
			 <td>
				<%
			   		   int count=search.number;			 
				       int temp=hits.size();
                       if(temp > count) temp=count;
					   System.out.println(query+"\t"+count+"\t"+temp);
				       int N=0;
				       if(temp%5==0) 
				    	   N= temp/5;
				       else
				    	   N=temp/5+1;
				      
				       for(int j=0;j<N && j<4 ;j++)
				       {
				    	out.println("<tr>");
						for (int i = 0; i <=4 && (i+j*5)<temp; i++)
						{	
							System.out.println("rank="+(i+j*5));
						    Element doc = hits.get(i+j*5);  
						   
						    String name =doc.name;
						    String path ="temp.jpg";
						    int w =doc.Width/10;
						    int h=doc.Height/10;
						    int hh = 150;
						    int ww = w*hh/h;
						    if(ww>250) ww=250;
							out.println("<td width=\"160\">");
							out.println("<table width=\"160\" border=\"1\">");
							out.println("<tr>");
							out.println("<td>");
							out.println("<img  src=\""+path+"\" width="+"\""+ww+"\""+"height=\""+hh+"\" name=\"pic\" alt=\""+name+"\""+">");
							out.println("</td>");
							out.println("</tr>");
							out.println("<tr>");
							out.println(name);
							out.println("</tr>");
							out.println("<tr>");
							out.println(doc.Width+"X"+doc.Width);
							out.println("</tr>");	
							out.println("</table>");
							out.println("</td>");						    
						}
						 out.println("</tr>");
						
				       }
				       
				       for(int j=4;j<N;j++)
				       {
				    	out.println("<tr>");
						for (int i = 0; i <=4 && (i+j*5)<temp; i++)
						{	
							System.out.println("rank="+(i+j*5));
						    Element doc = hits.get(i+j*5);  
						   
						    String name =doc.name;
						    String path =doc.path;
						    int w =doc.Width/10;
						    int h=doc.Height/10;
						    //int hh=h;
						    //int ww=w;
						    //if(hh>210)
						    //{
						    //	hh=210;
						    //	ww = ww*hh/h;
						    //}
						    int hh = 150;
						    int ww = w*hh/h;
						    if(ww>250) ww=250;
							out.println("<td width=\"150\">");
							out.println("<table width=\"150\" border=\"1\">");
							out.println("<tr>");
							out.println("<td>");
							out.println("<img  src=\""+path+"\" width="+"\""+ww+"\""+"height=\""+hh+"\" name=\"pic\" alt=\""+name+"\""+">");
							out.println("</td>");
							out.println("</tr>");
							out.println("<tr>");
							out.println(name);
							out.println("</tr>");
							out.println("<tr>");
							out.println(doc.Width+"X"+doc.Width);
							out.println("</tr>");	
							out.println("</table>");
							out.println("</td>");						    
						}
						 out.println("</tr>");
						
				       }
					    
				%>
				<td>
			</tr>
		</table>
		</td>
	</tr>	
</table>	
 </body>
</html>